package com.endbd.warehouse.controller;

import com.endbd.feignapi.model.system.City;
import com.endbd.feignapi.model.system.Province;
import com.endbd.feignapi.model.system.User;
import com.endbd.feignapi.model.warehouse.Warehouse;
import com.endbd.feignapi.util.PageModel;
import com.endbd.warehouse.model.CityCondition;
import com.endbd.warehouse.model.ProvinceCondition;
import com.endbd.warehouse.model.UserCondition;
import com.endbd.warehouse.model.WarehouseCondition;
import com.endbd.warehouse.service.IManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/warehouse")
public class WarehouseAction {
    @Autowired
    private IManageService manageService;

    public IManageService getManageService() {
        return manageService;
    }
    public void setManageService(IManageService manageService) {
        this.manageService = manageService;
    }

    @RequestMapping("/pageBean")
    @ResponseBody
    public PageModel<Warehouse> queryWareHousePageBean(WarehouseCondition wc,PageModel<Warehouse> pageModel){
        PageModel<Warehouse> pageBean = manageService.queryWarehouses(wc,pageModel);
        return pageBean;
    }


    @RequestMapping("/queryWareAll")
    @ResponseBody
    public List<Warehouse> queryWares(WarehouseCondition wc){
        return manageService.queryAll(wc);
    }

    @RequestMapping("/queryPronvice")
    @ResponseBody
    public List<Province> queryProvince(ProvinceCondition pc){
        return manageService.queryProvinces(pc);
    }

    @RequestMapping("/queryCity")
    @ResponseBody
    public List<City> qqueryCity(CityCondition cc){
        return manageService.queryCitys(cc);
    }


//    查询一个数据
    @RequestMapping("/queryWare")
    @ResponseBody
    public Warehouse querOne(WarehouseCondition wc){
        Warehouse wh = manageService.queryWarehouse(wc);
        return wh;
    }

//    修改状态
    @RequestMapping("/updateState")
    @ResponseBody
    public int updateState(String id){
        int count = manageService.changeState(id);
        return count;
    }

//    修改状态
    @RequestMapping("/recoverState")
    @ResponseBody
    public int recoverState(String id){
        int count = manageService.recoverState(id);
        return count;
    }

//    修改数据
    @RequestMapping("/updateWarehouse")
    @ResponseBody
    public int updateWarehouse(Warehouse wh){
        System.out.println(wh);
        int count = manageService.updateWarehouse(wh);
        return count;
    }

//    查询财务部的仓库管理员
    @RequestMapping("/queryUsers")
    @ResponseBody
    public List<User> queryUsers(UserCondition userCondition){
        return manageService.queryUsers(userCondition);
    }

//增加一条仓库记录
    @RequestMapping("/addWare")
    @ResponseBody
    public int addWare(Warehouse warehouse){
        int count = manageService.insertone(warehouse);
        return count;
    }
}
